//index.js
//获取应用实例
const app = getApp()
var t = require('./../../utils/request.js');
var u = require('./../../utils/util.js');

Page({
  data: {
    checked: false,
    uname: '',
    password: ''
  },

  onLoad: function () {
    if (wx.getStorageSync('checked')) {
      this.setData({
        checked: wx.getStorageSync('checked'),
        uname: wx.getStorageSync('uname'),
        password: wx.getStorageSync('password')
      })
    }
  },
  scanQr: function () {
  },
  getUserInfo: function(e) {
  },
  toSgin: function () {
    wx.navigateTo({
      url: '/pages/sgin/sgin',
    })
  },
  onChange: function (event) {
    this.setData({
      checked: event.detail
    })
  },
  inputPhone: function (e) {
    this.setData({
      uname: e.detail.value
    })
  },
  inputPassword: function (e) {
    this.setData({
      password: e.detail.value
    })
  },
  loginSystem: function () {
    wx.showLoading({
      title: '登录中..',
    })
    t.toPost('/minip/seller/login', {
      uname: this.data.uname,
      password: this.data.password
    }, (res) => {
      console.log(res)
      if (res.code == '000000') {
        wx.hideLoading()
        if (this.data.checked) {
          wx.setStorageSync('checked', true)
          wx.setStorageSync('uname', this.data.uname)
          wx.setStorageSync('password', this.data.password)
        } else {
          wx.setStorageSync('checked', false)
          wx.setStorageSync('uname', '')
          wx.setStorageSync('password', '')
        }
        wx.setStorageSync('sid', res.data)
        wx.redirectTo({
          url: '/pages/home/home',
        })

        wx.showToast({
          title: '登录成功'
        })
      } else {
        wx.showToast({
          icon: 'none',
          title: res.message
        })
      }
    })
  },

  toSms: function () {
    wx.navigateTo({
      url: '/pages/sms/sms',
    })
  },

  /**
    * 用户点击右上角分享
  */
  onShareAppMessage: function () {
    return {
      title: '经销商核销系统',
      path: '/pages/index/index',
      imageUrl: 'http://qny.zhiniugroup.com/blog/20190109144655.png',
      success: function (res) {
        console.log(res, '分享成功')
      }
    }
  }
})
